//
//  BarrierRwlockDemo.m
//  OCLockDemo
//
//  Created by lianglibao on 2018/12/22.
//  Copyright © 2018年 梁立保. All rights reserved.
//

#import "BarrierRwlockDemo.h"
static dispatch_queue_t queue;
@implementation BarrierRwlockDemo

+ (void)initialize {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        queue = dispatch_queue_create("rw_queue", DISPATCH_QUEUE_CONCURRENT);
    });
}

+ (void)barrierRwlockTest {
for (int i = 0; i < 10; i++) {
    dispatch_async(queue, ^{
        [self read];
    });
    
    dispatch_async(queue, ^{
        [self read];
    });
    
    dispatch_async(queue, ^{
        [self read];
    });
    
    dispatch_barrier_async(queue, ^{
        [self write];
    });
}
}


+ (void)read {
    sleep(1);
    NSLog(@"read");
}

+ (void)write {
    sleep(1);
    NSLog(@"write");
}

@end
